﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Poco;
using Metier;

namespace WebApp.Controllers
{
    [Authorize(Roles="Cuisinier")]
    public class CuisineController : Controller
    {
        /*Restaurant restaurant = null;
        GestionCommande gestCommandes = null;

        public CuisineController ()
        {
            GestionRestaurant gestRestaurant = new GestionRestaurant();
            GestionCuisinier gestCuisinier = new GestionCuisinier();

            Cuisinier cuisinier = gestCuisinier.Chercher(User.Identity.Name);

            restaurant = gestRestaurant.Chercher(cuisinier.Restaurant.Id);

            gestCommandes = new GestionCommande();
        }*/

        GestionPreparationPlat preparationPlat = new GestionPreparationPlat();
        GestionCuisinier gestionCuisinier = new GestionCuisinier();

        public ActionResult Index()
        {
            CuisineModelView cuisinemodelview = new CuisineModelView();
            using (Context db = new Context())
                {
            List<PreparationPlat> preparationDePtiPlats = (from p in db.PreparationPlats select p).ToList();
            
            foreach (PreparationPlat plat in preparationDePtiPlats)
            {
                EtatPlat etatPlat = plat.getEtatCommande() ;

                switch(etatPlat)
                {
                    case EtatPlat.EnAttenteCuisine :
                        cuisinemodelview.platAttente.Add(plat);
                        break;
                    case EtatPlat.EnPreparation :
                        cuisinemodelview.prepPlat.Add(plat);
                        break;
                    case EtatPlat.PlatPret :
                        cuisinemodelview.platPret.Add(plat);
                        break;                        
                }                
            }
                }
        
            cuisinemodelview.cuisiniers = gestionCuisinier.Lister();

            return View(cuisinemodelview);
        }


       /* public ActionResult ListeCuisinier ()
        {
            GestionCuisinier gestCuistot = new GestionCuisinier();

            List<Cuisinier> cuisiniers = gestCuistot.Lister(restaurant);

            return PartialView(cuisiniers);
        }

        public ActionResult PlatsEnAttente ()
        {
            List<PreparationPlat> plats = gestCommandes.Lister(restaurant, EtatPlat.EnAttenteCuisine.ToString());

            return View(plats);
        }

        public ActionResult PlatsEnCours ()
        {
            List<PreparationPlat> plats = gestCommandes.Lister(restaurant, EtatPlat.EnPreparation.ToString());

            return View(plats);
        }

        //public ActionResult PriseDePlat (PreparationPlat p, int cuisinierId)
        //{

        //}*/
    }
}
